@extends('admin::layouts.master')
@section('content')
    @component('components.tabs', ['title' => '栏目列表'])
        @slot('nav')
            <li class="nav-item"><a class="nav-link active" href="#home">栏目管理</a></li>
            <li class="nav-item"><a class="nav-link" href="/article/category/create">添加栏目</a></li>
        @endslot
        @slot('body')
            <table class="table">
                <thead>
                <tr>
                    <th style="width:10%;">编号</th>
                    <th>栏目名称</th>
                    <th>创建时间</th>
                    <th>编辑时间</th>
                    <th class="actions"></th>
                </tr>
                </thead>
                <tbody>
                @foreach($categories as $category)
                    <tr>
                        <td>{{ $category['id'] }}</td>
                        <td>{!! $category['_name'] !!}</td>
                        <td>{{ $category['created_at'] }}</td>
                        <td>{{ $category['updated_at'] }}</td>
                        <td>
                            <div class="btn-group btn-space">
                                <button class="btn btn-secondary" type="button" onclick="delCategory({{ $category['id'] }}, this)">删除</button>
                                <form action="/article/category/{{ $category['id'] }}" hidden method="post">
                                    @csrf @method('DELETE')
                                </form>
                                <a href="/article/category/{{ $category['id'] }}/edit" class="btn btn-secondary">编辑</a>
                            </div>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        @endslot
    @endcomponent
@endsection
@section('scripts')
    <script>
        function delCategory(id, bt) {
            if (confirm('确定删除栏目吗?')) {
                $(bt).next('form').trigger('submit');
            }
        }
    </script>
@endsection